const int buttonPin = 2;   //button pin
const int ledPin = 7;   //LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  Serial.begin(9600);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);  //按键按下时led灯亮
  }
  else if (buttonState == LOW) {
    digitalWrite(ledPin, LOW);   //按键松开时led灯灭
  }
}
